package svc.elib.analysis;

import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

import svc.elib.db.Author;
import svc.elib.db.Database;
import svc.elib.socnet.CentralityMetrics;
import svc.elib.socnet.EvolutionarySnapshots;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;

public class ErodsBC {
	
	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		System.out.println(db.info());
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		
		String[] authorNames = {
				"Erdös_Paul",
				"Karamata_Jovan",
				"Gutman_Ivan",
				"Mijajlović_Žarko",	
		};
		
		System.out.print("year");
		for (int i = 0; i < authorNames.length; i++) {
			System.out.print(authorNames[i] + ", ");
		}
		System.out.println();
		
		EvolutionarySnapshots es = new EvolutionarySnapshots(net);
		Net[] snaps = es.getSnapshots();
		int startYear = es.getStartYear();
		
		for (int i = 0; i < snaps.length - 1; i++) {
			int year = startYear + i + 1;
			Net current = snaps[i];
			CentralityMetrics cmCurrent = new CentralityMetrics(current);
			cmCurrent.computeBetweeness(false);
			
			Iterator<Author> ait = current.getGraph().getVertices().iterator();
			
			LinkedList<Double> scoreList = new LinkedList<Double>();
			while (ait.hasNext()) {
				Author a = ait.next();
				double b1 = cmCurrent.getBetweenness(a.getName());
				scoreList.add(b1);
			}
			
			Collections.sort(scoreList);
			
			System.out.print(year + ", ");
			for (int j = 0; j < authorNames.length; j++) {
				String aName = authorNames[j];
				Author a = current.findAuthor(aName);
				if (a != null) {
					double score = cmCurrent.getBetweenness(a.getName());
					int pos = 1;
					for (int k = 0; k < scoreList.size(); k++) {
						if (scoreList.get(k) > score)
							++pos;
					}
					
					System.out.print(pos + ", ");
				}
				else
					System.out.print("-, ");
			}
			
			System.out.println();
		}
	}

}
